home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / GB-PVR 1.2.13 / GBPVR10213.msi / Cabs.w1.cab / TreeViewAdapter.js153 < prev    next >
Text File  |  2006-10-12  |  4KB  |  119 lines

  1. ∩╗┐var collapseClass = "AspNet-TreeView-Collapse";
  2. var expandClass = "AspNet-TreeView-Expand";
  3. var showClass = "AspNet-TreeView-Show";
  4. var hideClass = "AspNet-TreeView-Hide";
  5.  
  6. function IsExpanded__AspNetTreeView(element)
  7. {
  8.     return (HasClass__CssFriendlyAdapters(element, collapseClass));
  9. }
  10.  
  11. function TogglePlusMinus__AspNetTreeView(element, showPlus)
  12. {
  13.     if (HasAnyClass__CssFriendlyAdapters(element))
  14.     {
  15.         var showPlusLocal = IsExpanded__AspNetTreeView(element);
  16.         if ((typeof(showPlus) != "undefined") && (showPlus != null))
  17.         {
  18.             showPlusLocal = showPlus;
  19.         }    
  20.         var oldClass = showPlusLocal ? collapseClass : expandClass;
  21.         var newClass = showPlusLocal ? expandClass : collapseClass;
  22.         SwapClass__CssFriendlyAdapters(element, oldClass, newClass);
  23.     }
  24. }
  25.  
  26. function ToggleChildrenDisplay__AspNetTreeView(element, collapse)
  27. {
  28.     if ((element != null) && (element.parentNode != null) && (element.parentNode.getElementsByTagName != null))
  29.     {    
  30.         var childrenToHide = element.parentNode.getElementsByTagName("ul");
  31.         var oldClass = collapse ? showClass : hideClass;
  32.         var newClass = collapse ? hideClass : showClass;
  33.         for (var i=0; i<childrenToHide.length; i++)
  34.         {
  35.             if ((childrenToHide[i].parentNode != null) && (childrenToHide[i].parentNode == element.parentNode))
  36.             {
  37.                 SwapOrAddClass__CssFriendlyAdapters(childrenToHide[i], oldClass, newClass);
  38.             }
  39.         }
  40.     }
  41. }
  42.  
  43. function ExpandCollapse__AspNetTreeView(sourceElement)
  44. {
  45.     if (HasAnyClass__CssFriendlyAdapters(sourceElement))
  46.     {
  47.         var expanded = IsExpanded__AspNetTreeView(sourceElement);
  48.         TogglePlusMinus__AspNetTreeView(sourceElement, expanded);
  49.         ToggleChildrenDisplay__AspNetTreeView(sourceElement, expanded);
  50.     }
  51. }
  52.  
  53. function GetViewState__AspNetTreeView(id)
  54. {
  55.     var retStr = "";
  56.     if ((typeof(id) != "undefined") && (id != null) && (document.getElementById(id) != null))
  57.     {
  58.         var topUL = document.getElementById(id);
  59.         retStr = ComposeViewState__AspNetTreeView(topUL, "");        
  60.     }
  61.     return retStr;
  62. }
  63.  
  64. function ComposeViewState__AspNetTreeView(element, state)
  65. {
  66.     var child = element.firstChild;
  67.     var bConsiderChildren = true;
  68.  
  69.     //  The following line must be changed if you alter the TreeView adapters generation of
  70.     //  markup such that the first child within the LI no longer is the expand/collapse <span>.
  71.     if ((element.tagName == "LI") && (child != null))
  72.     {
  73.         var expandCollapseSPAN = null;
  74.         var currentChild = child;
  75.         while (currentChild != null)
  76.         {
  77.             if ((currentChild.tagName == "SPAN") &&
  78.                 (currentChild.className != null) &&
  79.                 ((currentChild.className.indexOf(collapseClass) > -1) ||
  80.                  (currentChild.className.indexOf(expandClass) > -1)))
  81.             {
  82.                 expandCollapseSPAN = currentChild;
  83.                 break;
  84.             }
  85.             currentChild = currentChild.nextSibling;
  86.         }
  87.     
  88.         if (expandCollapseSPAN != null)
  89.         {
  90.             if (expandCollapseSPAN.className.indexOf(collapseClass) > -1)
  91.             {
  92.                 //  If the "collapse" class is currently being used then the "collapse" icon is, presumably, being shown.
  93.                 //  In other words, the node itself is actually expanded at the present moment (which is why you now
  94.                 //  have the option of collapsing it.  So we mark it as an "expanded" node for purposes of the view state
  95.                 //  we are now accumulating.
  96.                 state +=  "e";
  97.             }
  98.             else if (expandCollapseSPAN.className.indexOf(expandClass) > -1)
  99.             {
  100.                 //  This part of the tree is collapsed so we don't need to consider its children.
  101.                 bConsiderChildren = false;
  102.                 state +=  "n";
  103.             }
  104.         }
  105.     }
  106.         
  107.     if (bConsiderChildren && (child != null))
  108.     {
  109.         state = ComposeViewState__AspNetTreeView(child, state);
  110.     }
  111.     
  112.     if (element.nextSibling != null)
  113.     {
  114.         state = ComposeViewState__AspNetTreeView(element.nextSibling, state);
  115.     }
  116.     
  117.     return state;
  118. }
  119.